#!/bin/sh
#
# GCC 2.95.4 Installer
#
function check {
	if [ ! -d gg: ]; then
		echo "DevEnv is not present in this system"
		exit 1
	fi
	if [ ! -f gg:gcc-2.95.4.tar.gz ]; then
		echo "Can't locate gg:gcc-2.95.4.tar.gz"
		exit 1
	fi
}
#
function backup {
	# Create backup directory
	if [ ! -d gg:__Tmp-Gcc-Backup__ ]; then
		mkdir gg:__Tmp-Gcc-Backup__ gg:__Tmp-Gcc-Backup__/bin gg:__Tmp-Gcc-Backup__/include gg:__Tmp-Gcc-Backup__/info gg:__Tmp-Gcc-Backup__/lib gg:__Tmp-Gcc-Backup__/lib/gcc-lib gg:__Tmp-Gcc-Backup__/lib/gcc-lib/ppc-morphos gg:__Tmp-Gcc-Backup__/man gg:__Tmp-Gcc-Backup__/man/man1 gg:__Tmp-Gcc-Backup__/ppc-morphos
	fi
	# Copy files (bin)
	mv gg:bin/c++filt		gg:__Tmp-Gcc-Backup__/bin
	mv gg:bin/cpp			gg:__Tmp-Gcc-Backup__/bin
	mv gg:bin/g++			gg:__Tmp-Gcc-Backup__/bin
	mv gg:bin/gcc			gg:__Tmp-Gcc-Backup__/bin
	mv gg:bin/gcov			gg:__Tmp-Gcc-Backup__/bin
	mv gg:bin/protoize	gg:__Tmp-Gcc-Backup__/bin
	mv gg:bin/unprotoize	gg:__Tmp-Gcc-Backup__/bin
	# Copy files (include)
	mv gg:include/g++-3	gg:__Tmp-Gcc-Backup__/include
	# Copy files (info)
	mv gg:info/cpp*		gg:__Tmp-Gcc-Backup__/info
	mv gg:info/gcc*		gg:__Tmp-Gcc-Backup__/info
	# Copy files (lib)
	mv gg:lib/libiberty.a	gg:__Tmp-Gcc-Backup__/lib
	mv gg:lib/gcc-lib/ppc-morphos/2.95.3 gg:__Tmp-Gcc-Backup__/lib/gcc-lib/ppc-morphos
	mv gg:lib/libb32			gg:__Tmp-Gcc-Backup__/lib
	mv gg:lib/libstdc++*		gg:__Tmp-Gcc-Backup__/lib
	# Copy files (man)
	mv gg:man/man1/cccp.*	gg:__Tmp-Gcc-Backup__/man/man1
	mv gg:man/man1/cpp.*		gg:__Tmp-Gcc-Backup__/man/man1
	mv gg:man/man1/g++.*		gg:__Tmp-Gcc-Backup__/man/man1
	mv gg:man/man1/gcc.*		gg:__Tmp-Gcc-Backup__/man/man1
	# Copy files (ppc-morphos)
	mv gg:ppc-morphos/include	gg:__Tmp-Gcc-Backup__/ppc-morphos
	# TarGZ
	cd gg:__Tmp-Gcc-Backup__
	tar -czpf ../gcc-2.95.3.tar.gz *
	cd gg:
	rm -fr gg:__Tmp-Gcc-Backup__
}
#
function install {
	cd gg:
	tar -xzf gcc-2.95.4.tar.gz
}
#
# Main
#
check
backup
install
